from time import sleep

from selenium.webdriver.common.by import By

from base.BasePage import BasePage
from common.DriverTools import DriverTools
from page.HomePage import HomePage


class LoginPage(BasePage):
    # 初始化实例属性
    def __init__(self):
        super().__init__()
        # 用户名
        self.user = (By.ID, 'username')
        # 密码
        self.password = (By.ID, 'password')
        # 验证码
        self.verify_code = (By.ID, 'verify_code')
        # 登陆按钮
        self.login_btn = (By.CLASS_NAME, 'J-login-submit')

    # 定义登陆的方法
    def login(self, user, pwd, code):
        # self.driver.find_element(*self.user).send_keys(user)
        self.input(self.find_el(*self.user), user)
        self.driver.find_element(*self.password).send_keys(pwd)
        self.driver.find_element(*self.verify_code).send_keys(code)
        self.driver.find_element(*self.login_btn).click()


if __name__ == '__main__':
    driver = DriverTools.get_driver()
    driver.get("http://hmshop-test.itheima.net/")
    HomePage().goto_login_page()
    sleep(3)
    LoginPage().login("13012345678", '123456', '8888')
    sleep(3)
    driver.quit()
